home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / funct.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  70 lines

  1. ; $Id: funct.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1982-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6.  
  7. PRO    FUNCT,X,A,F,PDER
  8. ;+
  9. ; NAME:
  10. ;    FUNCT
  11. ;
  12. ; PURPOSE:
  13. ;    Evaluate the sum of a Gaussian and a 2nd-order polynomial
  14. ;    and optionally return the value of its partial derivatives.
  15. ;    Normally, this function is used by CURVEFIT to fit the
  16. ;    sum of a line and a varying background to actual data.
  17. ;
  18. ; CATEGORY:
  19. ;    E2 - Curve and surface fitting.
  20. ;
  21. ; CALLING SEQUENCE:
  22. ;    FUNCT, X, A, F [, Pder]
  23. ;
  24. ; INPUTS:
  25. ;    X:    The values of the independent variable.
  26. ;    A:    The parameters of the equation described in PROCEDURE below.
  27. ;
  28. ; OUTPUTS:
  29. ;    F:    The value of the function at each X(i).
  30. ;
  31. ; OPTIONAL OUTPUT PARAMETERS:
  32. ;    Pder:    An array of the size (N_ELEMENTS(X),6) that contains the
  33. ;        partial derivatives.  Pder(i,j) represents the derivative
  34. ;        at the i'th point with respect to j'th parameter.
  35. ;
  36. ; COMMON BLOCKS:
  37. ;    None.
  38. ;
  39. ; SIDE EFFECTS:
  40. ;    None.
  41. ;
  42. ; RESTRICTIONS:
  43. ;    None.
  44. ;
  45. ; PROCEDURE:
  46. ;    F = A(0)*EXP(-Z^2/2) + A(3) + A(4)*X + A(5)*X^2
  47. ;    Z = (X-A(1))/A(2)
  48. ;
  49. ; MODIFICATION HISTORY:
  50. ;    WRITTEN, DMS, RSI, SEPT, 1982.
  51. ;    Modified, DMS, Oct 1990.  Avoids divide by 0 if A(2) is 0.
  52. ;-
  53.     ON_ERROR,2                        ;Return to caller if an error occurs
  54.     if a[2] ne 0.0 then Z = (X-A[1])/A[2] $    ;GET Z
  55.     else z= 10.
  56.     EZ = EXP(-Z^2/2.)*(ABS(Z) LE 7.) ;GAUSSIAN PART IGNORE SMALL TERMS
  57.     F = A[0]*EZ + A[3] + A[4]*X + A[5]*X^2 ;FUNCTIONS.
  58.     IF N_PARAMS(0) LE 3 THEN RETURN ;NEED PARTIAL?
  59. ;
  60.     PDER = FLTARR(N_ELEMENTS(X),6) ;YES, MAKE ARRAY.
  61.     PDER[0,0] = EZ        ;COMPUTE PARTIALS
  62.     if a[2] ne 0. then PDER[0,1] = A[0] * EZ * Z/A[2]
  63.     PDER[0,2] = PDER[*,1] * Z
  64.     PDER[*,3] = 1.
  65.     PDER[0,4] = X
  66.     PDER[0,5] = X^2
  67.     RETURN
  68. END
  69.  
  70.